package com.itita.ww2.utils;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.joda.time.DateTime;

import com.sohu.idcenter.IdWorker;

public class UUIDGenerator {
	private static volatile IdWorker idWorker = new IdWorker(new DateTime(2016, 1, 1, 0, 0).getMillis());
	private static Lock lock = new ReentrantLock();

	private static final String nextId(CharSequence prefix) {
		lock.lock();
		StringBuilder sb = new StringBuilder();
		try {
			sb.append(prefix);
			sb.append(Long.toHexString(idWorker.getId()));
		} finally {
			lock.unlock();
		}
		return sb.toString();
	}

	public static final String nextBattleLogId() {
		return nextId("bl");
	}

	public static final String nextItemId() {
		return nextId("I");
	}

	public static final String nextUserName() {
		return nextId("u");
	}

	public static final String nextOrderId() {
		return nextId("O");
	}

	public static final String nextAllianceId() {
		return nextId("a");
	}

	public static final String nextConstructionId() {
		return nextId("C");
	}
}
